<template>
  <div class="add-card">
    <header class="add-header">
      <el-page-header :content="title" @back="$router.back()" />
    </header>
    <main class="add-main">
      <div class="form-container">
        <div class="title">车辆信息</div>
        <div class="form">
          <el-form label-width="100px" :model="form" ref="form" :rules="rules">
            <el-form-item label="车主姓名" prop="personName">
                {{form.personName}}
              <!-- <el-input v-model="form.personName" /> -->
            </el-form-item>
            <el-form-item label="联系方式" prop="phoneNumber">
                {{form.phoneNumber}}
            
              <!-- <el-input v-model="form.phoneNumber" /> -->
            </el-form-item>
            <el-form-item label="车辆号码" prop="carNumber">
              <!-- <el-input v-model="form.carNumber" /> -->
              {{form.carNumber}}
            
            </el-form-item>
            <el-form-item label="车辆品牌" prop="carBrand">
              <!-- <el-input v-model="form.carBrand" /> -->
              {{form.carBrand}}
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="form-container">
        <div class="title">缴费记录</div>
        <div class="form">
            				
               <el-table
      :data="tableData"
      height="200"
      style="width: 100%">
      <el-table-column
     type="index"
        label="序号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="有效时间">
        <template slot-scope="scope">
            {{scope.row.cardStartDate}}至{{scope.row.cardEndDate}}
        </template>
      </el-table-column>
      <el-table-column
        prop="paymentAmount"
        label="支付金额"
>
      </el-table-column>
            <el-table-column
        prop="paymentMethod"
        label="支付方式"
>
      </el-table-column>
            <el-table-column
        prop="createTime"
        label="办理时间"
>
      </el-table-column>
            <el-table-column
        prop="createUser"
        label="办理人"
>
      </el-table-column>
    </el-table>
         </div>
      </div>
    </main>
     </div>
</template>

<script>
import { yuekaadd, yuekadetail1, yuekaedit } from "@/api/user";

export default {
  data() {
    const validateCarNumber = (rule, value, callback) => {
      const plateNumberRgex = /^[\u4E00-\u9FA5][\da-zA-Z]{6}$/;
      if (plateNumberRgex.test(value)) {
        callback();
      } else {
        callback(new Error("请输入正确的车牌号"));
      }
    };
    return {
        tableData:[],
      form: {
        paytime:[],
      },
      title: "增加月卡",
      value1: "",
      rules: {
        personName: [
          { required: true, message: "请输入车主姓名", trigger: "blur" },
        ],
        phoneNumber: [
          { required: true, message: "请输入联系方式", trigger: "blur" },
        ],
        carNumber: [
          { required: true, message: "请输入车辆号码", trigger: "blur" },
          { validator: validateCarNumber, trigger: "blur" },
        ],
        carBrand: [
          { required: true, message: "请输入车辆品牌", trigger: "blur" },
        ],
      },
      rules1: {
        paytime: [{ required: true, message: "请选择有效日期" }],
        paymentAmount: [
          { required: true, message: "请输入支付金额", trigger: "blur" },
        ],
        paymentMethod: [
          { required: true, message: "请选择支付方式", trigger: "change" },
        ],
      },
      list: [
        {
          industryCode: "Alipay",
          industryName: "支付宝",
        },
        {
          industryCode: "WeChat",
          industryName: "微信",
        },
        {
          industryCode: "Cash",
          industryName: "线下",
        },
      ],
    };
  },
  mounted() {
    if (this.$route.query.id) {
      this.title = "月卡详情";
      this.getdata();
    } else {
      this.title = "新增月卡";
    }
  },
  methods: {
    xgyxrq(e){
        console.log(e,"e");
        this.$forceUpdate()
    },
    async getdata() {
      const res = await yuekadetail1(this.$route.query.id);
      console.log(res, "res");
      this.form = res.data;
      this.tableData=res.data.rechargeList
    //   this.form.paytime = [res.data.cardStartDate, res.data.cardEndDate];
    },
    submit() {
      this.$refs.form.validate((valid) => {
        console.log(valid);
        if (valid) {
          this.$refs.form1.validate(async (valid) => {
            console.log(valid);
            console.log(this.form.paytime, "paytime");
            this.form.cardStartDate = this.form.paytime[0];
            this.form.cardEndDate = this.form.paytime[1];
            delete this.form.paytime;
            if (this.$route.query.id) {
                delete this.form.cardStatus
              const res = await yuekaedit(this.form);
              if (res.code == 10000) {
                this.$message.success("成功");
                this.$router.back();
              }
            } else {
              const res = await yuekaadd(this.form);
              if (res.code == 10000) {
                this.$message.success("成功");
                this.$router.back();
              }
            }
          });
        }
      });
    },
    chongzhi() {
      this.$refs.form.resetFields();
      this.$refs.form1.resetFields();
    },
  },
};
</script>

<style scoped lang="scss">
.add-card {
  background-color: #f4f6f8;
  height: 100vh;

  .add-header {
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 64px;
    background-color: #fff;

    .left {
      span {
        margin-right: 4px;
      }
      .arrow {
        cursor: pointer;
      }
    }

    .right {
      text-align: right;
    }
  }

  .add-main {
    background: #f4f6f8;
    padding: 20px 130px;

    .form-container {
      background-color: #fff;

      .title {
        height: 60px;
        line-height: 60px;
        padding-left: 20px;
      }

      .form {
        margin-bottom: 20px;
        padding: 20px 65px 24px;

        .el-form {
          display: flex;
          flex-wrap: wrap;

          .el-form-item {
            width: 50%;
          }
        }
      }
    }
    .preview {
      img {
        width: 100px;
      }
    }
  }

  .add-footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 24px 50px;
    color: #000000d9;
    font-size: 14px;
    background: #fff;
    text-align: center;
  }
}
</style>